<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="../ct-embedded-flakiness-dashboard.html">

<script>
(function () {

var assert = chai.assert;

describe('ct-embedded-flakiness-dashboard', function() {

  describe('iframe location', function() {
    var embeddedFlakinessDashboard;

    after(function() {
      document.body.removeChild(embeddedFlakinessDashboard);
    });

    it('should point the iframe to the dashboard', function(done) {
      var failure = new CTStepFailure('foo_tests', 'foo/bar.html');
      failure.embeddedFlakinessDashboardURL = function() {
        return 'placeholder.html?' + this.flakinessDashboardURL() + '&showChrome=false';
      }

      embeddedFlakinessDashboard = document.createElement('ct-embedded-flakiness-dashboard');
      embeddedFlakinessDashboard.hidden = true;
      embeddedFlakinessDashboard.test = failure;
      document.body.appendChild(embeddedFlakinessDashboard);

      var iframe = embeddedFlakinessDashboard.shadowRoot.querySelector('#iframe');
      iframe.addEventListener('load', function() {
        assert.include(iframe.contentWindow.location.href,
                       failure.embeddedFlakinessDashboardURL());
        done();
      });
    });
  });

  it('should respond to heightChanged', function(done) {
    var embeddedFlakinessDashboard = document.createElement('ct-embedded-flakiness-dashboard');

    var finishTest = function() {
      window.removeEventListener('message', finishTest);
      var iframe = embeddedFlakinessDashboard.shadowRoot.querySelector('#iframe');
      assert.equal(iframe.style.height, '100px');
      done();
    };

    window.addEventListener('message', finishTest);
    window.postMessage({command: 'heightChanged', height: "100"}, '*');
  });
});

})()
</script>
